#  一个简单的训练机器学习模型训练，作为fit的扩展, 输入训练数据, 模型 输出指标
def train(train_df, ModelClass, best_params, args, config):
    """
    在一个fold上训练和评估模型
    """
    # === 参数准备 ===
    params = best_params.copy() if best_params else {}
    if args.model == "svm":
        params["kernel"] = "linear"

    # === 初始化模型 ===
    model = ModelClass(random_state=args.seed, **params)

    # === 模型训练 ===
    model.fit(
        train_df,
        tune_params=args.tune,
        search_type=config.SEARCH_TYPE,
        cv_folds=config.CV_FOLDS,
        n_iter=config.N_ITER,
        scoring=config.SCORING_CLASSIFICATION if args.experiment == "classification" else config.SCORING_REGRESSION,
        n_jobs=config.N_JOBS,
        sensitive_analysis=args.sensitive
    )
    return model
